﻿
function setClipboard(maintext)
{
    if (window.clipboardData)
    {
        return (window.clipboardData.setData("Text", maintext));
    }
    else
    {
        if (window.netscape)
        {
            try
            {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
                if (!clip)
                {
                    return;
                }
                var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
                if (!trans)
                {
                    return;
                }
                trans.addDataFlavor("text/unicode");
                var str = new Object();
                var len = new Object();
                var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
                var copytext = maintext;
                str.data = copytext;
                trans.setTransferData("text/unicode", str, copytext.length * 2);
                var clipid = Components.interfaces.nsIClipboard;
                if (!clip)
                {
                    return false;
                }
                clip.setData(trans, null, clipid.kGlobalClipboard);
                return true;
            }
            catch (e)
            {
                alert("您的firefox安全限制限制您进行剪贴板操作，请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试，相对路径为firefox根目录/greprefs/all.js");
                return false;
            }

        }
    }
    return false;
}

function CopyToClipboard()
{
    var url = location.href;
    //var hint = document.getElementsByTagName("title").item.innerText; //document.getElementById(titleID).innerText;
    var msg = url + " ，感觉这篇文章挺不错的，你看看吧！";
    setClipboard(msg);
    alert("文章链接及标题已复制到剪贴板，您可以直接粘贴到你的QQ、MSN等聊天输入框中，群发给您的好友！");
}